package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.common.dto.SetmealDishFrontDto;
import com.itheima.reggie.entity.ShoppingCart;
import com.itheima.reggie.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车
 */
@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("add")
    public R<ShoppingCart> addToCart(@RequestBody ShoppingCart cart) {
        System.out.println(cart);
        return shoppingCartService.addToCart(cart);
    }

    @GetMapping("list")
    public R<List<ShoppingCart>> shoppingCartList() {
        return shoppingCartService.shoppingCartList();
    }

    @DeleteMapping("/clean")
    public R<String> deleteShoppingCart() {
        return shoppingCartService.deleteShoppingCart();
    }

    @PostMapping("/sub")
    public R<ShoppingCart> sub(@RequestBody SetmealDishFrontDto dto) {
        return shoppingCartService.sub(dto.getDishId(), dto.getSetmealId());
    }

}